<!DOCTYPE html>
<html >

<head>

  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>《属性数据分析》代码</title>
  <meta name="description" content="《属性数据分析》代码。">
  <meta name="generator" content="bookdown 0.7 and GitBook 2.6.7">

  <meta property="og:title" content="《属性数据分析》代码" />
  <meta property="og:type" content="book" />
  
  
  <meta property="og:description" content="《属性数据分析》代码。" />
  

  <meta name="twitter:card" content="summary" />
  <meta name="twitter:title" content="《属性数据分析》代码" />
  
  <meta name="twitter:description" content="《属性数据分析》代码。" />
  



<meta name="date" content="2018-09-05">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  
  
<link rel="prev" href="build-and-apply-logistic-model.html">
<link rel="next" href="r-pkg-intro.html">
<script src="libs/jquery/jquery.min.js"></script>
<link href="libs/gitbook/css/style.css" rel="stylesheet" />
<link href="libs/gitbook/css/plugin-bookdown.css" rel="stylesheet" />
<link href="libs/gitbook/css/plugin-highlight.css" rel="stylesheet" />
<link href="libs/gitbook/css/plugin-search.css" rel="stylesheet" />
<link href="libs/gitbook/css/plugin-fontsettings.css" rel="stylesheet" />









<style type="text/css">
a.sourceLine { display: inline-block; line-height: 1.25; }
a.sourceLine { pointer-events: none; color: inherit; text-decoration: inherit; }
a.sourceLine:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode { white-space: pre; position: relative; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
code.sourceCode { white-space: pre-wrap; }
a.sourceLine { text-indent: -1em; padding-left: 1em; }
}
pre.numberSource a.sourceLine
  { position: relative; left: -4em; }
pre.numberSource a.sourceLine::before
  { content: attr(data-line-number);
    position: relative; left: -1em; text-align: right; vertical-align: baseline;
    border: none; pointer-events: all; display: inline-block;
    -webkit-touch-callout: none; -webkit-user-select: none;
    -khtml-user-select: none; -moz-user-select: none;
    -ms-user-select: none; user-select: none;
    padding: 0 4px; width: 4em;
    color: #aaaaaa;
  }
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa;  padding-left: 4px; }
div.sourceCode
  {  }
@media screen {
a.sourceLine::before { text-decoration: underline; }
}
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
code span.at { color: #7d9029; } /* Attribute */
code span.bn { color: #40a070; } /* BaseN */
code span.bu { } /* BuiltIn */
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
code span.ch { color: #4070a0; } /* Char */
code span.cn { color: #880000; } /* Constant */
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
code span.dt { color: #902000; } /* DataType */
code span.dv { color: #40a070; } /* DecVal */
code span.er { color: #ff0000; font-weight: bold; } /* Error */
code span.ex { } /* Extension */
code span.fl { color: #40a070; } /* Float */
code span.fu { color: #06287e; } /* Function */
code span.im { } /* Import */
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
code span.op { color: #666666; } /* Operator */
code span.ot { color: #007020; } /* Other */
code span.pp { color: #bc7a00; } /* Preprocessor */
code span.sc { color: #4070a0; } /* SpecialChar */
code span.ss { color: #bb6688; } /* SpecialString */
code span.st { color: #4070a0; } /* String */
code span.va { color: #19177c; } /* Variable */
code span.vs { color: #4070a0; } /* VerbatimString */
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
</style>

<link rel="stylesheet" href="css/style.css" type="text/css" />
</head>

<body>



  <div class="book without-animation with-summary font-size-2 font-family-1" data-basepath=".">

    <div class="book-summary">
      <nav role="navigation">

<ul class="summary">
<li><a href="./index.html">《属性数据分析》代码</a></li>

<li class="divider"></li>
<li class="chapter" data-level="" data-path="index.html"><a href="index.html"><i class="fa fa-check"></i>前言</a></li>
<li class="chapter" data-level="1" data-path="intro.html"><a href="intro.html"><i class="fa fa-check"></i><b>1</b> 导言</a><ul>
<li class="chapter" data-level="1.1" data-path="intro.html"><a href="intro.html#data-intro"><i class="fa fa-check"></i><b>1.1</b> 属性响应数据</a></li>
<li class="chapter" data-level="1.2" data-path="intro.html"><a href="intro.html#prob-dist"><i class="fa fa-check"></i><b>1.2</b> 属性数据的概率分布</a><ul>
<li class="chapter" data-level="" data-path="intro.html"><a href="intro.html#二项分布计算"><i class="fa fa-check"></i>二项分布计算</a></li>
</ul></li>
<li class="chapter" data-level="1.3" data-path="intro.html"><a href="intro.html#stat-infer"><i class="fa fa-check"></i><b>1.3</b> 比例的统计推断</a><ul>
<li class="chapter" data-level="" data-path="intro.html"><a href="intro.html#二项分布似然函数图"><i class="fa fa-check"></i>二项分布似然函数图</a></li>
<li class="chapter" data-level="" data-path="intro.html"><a href="intro.html#二项分布假设检验"><i class="fa fa-check"></i>二项分布假设检验</a></li>
<li class="chapter" data-level="" data-path="intro.html"><a href="intro.html#二项分布置信区间"><i class="fa fa-check"></i>二项分布置信区间</a></li>
</ul></li>
<li class="chapter" data-level="1.4" data-path="intro.html"><a href="intro.html#more-stat-infer"><i class="fa fa-check"></i><b>1.4</b> 关于离散数据的更多统计推断</a><ul>
<li class="chapter" data-level="" data-path="intro.html"><a href="intro.html#二项分布参数统计推断"><i class="fa fa-check"></i>二项分布参数统计推断</a></li>
<li class="chapter" data-level="" data-path="intro.html"><a href="intro.html#小样本推断"><i class="fa fa-check"></i>小样本推断</a></li>
<li class="chapter" data-level="" data-path="intro.html"><a href="intro.html#小样本推断p值调整"><i class="fa fa-check"></i>小样本推断P值调整</a></li>
</ul></li>
<li class="chapter" data-level="" data-path="intro.html"><a href="intro.html#problems-ch1"><i class="fa fa-check"></i>课后题</a><ul>
<li class="chapter" data-level="" data-path="intro.html"><a href="intro.html#第4题"><i class="fa fa-check"></i>第4题</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="2" data-path="contingency-table.html"><a href="contingency-table.html"><i class="fa fa-check"></i><b>2</b> 列联表</a><ul>
<li class="chapter" data-level="2.1" data-path="contingency-table.html"><a href="contingency-table.html#stucture"><i class="fa fa-check"></i><b>2.1</b> 列联表的概率结构</a><ul>
<li class="chapter" data-level="" data-path="contingency-table.html"><a href="contingency-table.html#关于来世"><i class="fa fa-check"></i>关于来世</a></li>
</ul></li>
<li class="chapter" data-level="2.2" data-path="contingency-table.html"><a href="contingency-table.html#prop-compare"><i class="fa fa-check"></i><b>2.2</b> 2×2表比例的比较</a><ul>
<li class="chapter" data-level="" data-path="contingency-table.html"><a href="contingency-table.html#阿司匹林与心脏病列联表检验"><i class="fa fa-check"></i>阿司匹林与心脏病（列联表检验）</a></li>
</ul></li>
<li class="chapter" data-level="2.3" data-path="contingency-table.html"><a href="contingency-table.html#odds-ratio"><i class="fa fa-check"></i><b>2.3</b> 优势比</a><ul>
<li class="chapter" data-level="" data-path="contingency-table.html"><a href="contingency-table.html#阿司匹林与心脏病优势比"><i class="fa fa-check"></i>阿司匹林与心脏病（优势比）</a></li>
<li class="chapter" data-level="" data-path="contingency-table.html"><a href="contingency-table.html#吸烟状态与心肌梗死"><i class="fa fa-check"></i>吸烟状态与心肌梗死</a></li>
</ul></li>
<li class="chapter" data-level="2.4" data-path="contingency-table.html"><a href="contingency-table.html#chi-square-test"><i class="fa fa-check"></i><b>2.4</b> 独立性的卡方检验</a><ul>
<li class="chapter" data-level="" data-path="contingency-table.html"><a href="contingency-table.html#性别和党派认同"><i class="fa fa-check"></i>性别和党派认同</a></li>
</ul></li>
<li class="chapter" data-level="2.5" data-path="contingency-table.html"><a href="contingency-table.html#indenpendence-test-for-ordinal-data"><i class="fa fa-check"></i><b>2.5</b> 有序数据的独立性检验</a><ul>
<li class="chapter" data-level="" data-path="contingency-table.html"><a href="contingency-table.html#饮酒与婴儿畸形"><i class="fa fa-check"></i>饮酒与婴儿畸形</a></li>
</ul></li>
<li class="chapter" data-level="2.6" data-path="contingency-table.html"><a href="contingency-table.html#exact-test-for-small-sample"><i class="fa fa-check"></i><b>2.6</b> 小样本的精确推断</a><ul>
<li class="chapter" data-level="" data-path="contingency-table.html"><a href="contingency-table.html#女士品茶"><i class="fa fa-check"></i>女士品茶</a></li>
</ul></li>
<li class="chapter" data-level="2.7" data-path="contingency-table.html"><a href="contingency-table.html#three-way-table"><i class="fa fa-check"></i><b>2.7</b> 三项列联表的关联性</a><ul>
<li class="chapter" data-level="" data-path="contingency-table.html"><a href="contingency-table.html#死刑判决案例"><i class="fa fa-check"></i>死刑判决案例</a></li>
<li class="chapter" data-level="" data-path="contingency-table.html"><a href="contingency-table.html#临床试验"><i class="fa fa-check"></i>临床试验</a></li>
</ul></li>
<li class="chapter" data-level="" data-path="contingency-table.html"><a href="contingency-table.html#problems-ch2"><i class="fa fa-check"></i>课后题</a><ul>
<li class="chapter" data-level="" data-path="contingency-table.html"><a href="contingency-table.html#第18题"><i class="fa fa-check"></i>第18题</a></li>
<li class="chapter" data-level="" data-path="contingency-table.html"><a href="contingency-table.html#第22题"><i class="fa fa-check"></i>第22题</a></li>
<li class="chapter" data-level="" data-path="contingency-table.html"><a href="contingency-table.html#第33题"><i class="fa fa-check"></i>第33题</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="3" data-path="glm.html"><a href="glm.html"><i class="fa fa-check"></i><b>3</b> 广义线性模型</a><ul>
<li class="chapter" data-level="3.1" data-path="glm.html"><a href="glm.html#components-of-glm"><i class="fa fa-check"></i><b>3.1</b> 广义线性模型的构成部分</a></li>
<li class="chapter" data-level="3.2" data-path="glm.html"><a href="glm.html#glm-for-binary-data"><i class="fa fa-check"></i><b>3.2</b> 二分数据的广义线性模型</a><ul>
<li class="chapter" data-level="" data-path="glm.html"><a href="glm.html#打鼾与心脏病"><i class="fa fa-check"></i>打鼾与心脏病</a></li>
</ul></li>
<li class="chapter" data-level="3.3" data-path="glm.html"><a href="glm.html#glm-for-count-data"><i class="fa fa-check"></i><b>3.3</b> 计数数据的广义线性模型</a><ul>
<li class="chapter" data-level="" data-path="glm.html"><a href="glm.html#母鲎及其追随者泊松glm"><i class="fa fa-check"></i>母鲎及其追随者（泊松GLM）</a></li>
<li class="chapter" data-level="" data-path="glm.html"><a href="glm.html#母鲎及其追随者负二项glm"><i class="fa fa-check"></i>母鲎及其追随者（负二项GLM）</a></li>
<li class="chapter" data-level="" data-path="glm.html"><a href="glm.html#英国的火车事故"><i class="fa fa-check"></i>英国的火车事故</a></li>
</ul></li>
<li class="chapter" data-level="3.4" data-path="glm.html"><a href="glm.html#stat-infer-glm"><i class="fa fa-check"></i><b>3.4</b> 统计推断和模型检验</a><ul>
<li class="chapter" data-level="" data-path="glm.html"><a href="glm.html#打鼾与心脏病-1"><i class="fa fa-check"></i>打鼾与心脏病</a></li>
</ul></li>
<li class="chapter" data-level="3.5" data-path="glm.html"><a href="glm.html#fit-glm"><i class="fa fa-check"></i><b>3.5</b> 广义线性模型的拟合</a></li>
<li class="chapter" data-level="" data-path="glm.html"><a href="glm.html#problems-ch3"><i class="fa fa-check"></i>课后题</a><ul>
<li class="chapter" data-level="" data-path="glm.html"><a href="glm.html#第3题"><i class="fa fa-check"></i>第3题</a></li>
<li class="chapter" data-level="" data-path="glm.html"><a href="glm.html#第4题-1"><i class="fa fa-check"></i>第4题</a></li>
<li class="chapter" data-level="" data-path="glm.html"><a href="glm.html#第7题"><i class="fa fa-check"></i>第7题</a></li>
<li class="chapter" data-level="" data-path="glm.html"><a href="glm.html#第20题"><i class="fa fa-check"></i>第20题</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="4" data-path="logistic-regression.html"><a href="logistic-regression.html"><i class="fa fa-check"></i><b>4</b> logistic回归</a><ul>
<li class="chapter" data-level="4.1" data-path="logistic-regression.html"><a href="logistic-regression.html#interpret-logistic"><i class="fa fa-check"></i><b>4.1</b> logistic回归模型的解释</a><ul>
<li class="chapter" data-level="" data-path="logistic-regression.html"><a href="logistic-regression.html#母鲎及其追随者logistic回归"><i class="fa fa-check"></i>母鲎及其追随者（logistic回归）</a></li>
</ul></li>
<li class="chapter" data-level="4.2" data-path="logistic-regression.html"><a href="logistic-regression.html#infer-logistic"><i class="fa fa-check"></i><b>4.2</b> logistic回归的推断</a></li>
<li class="chapter" data-level="4.3" data-path="logistic-regression.html"><a href="logistic-regression.html#cate-var-logistic"><i class="fa fa-check"></i><b>4.3</b> 属性预测变量的logistic回归</a><ul>
<li class="chapter" data-level="" data-path="logistic-regression.html"><a href="logistic-regression.html#azt和aids"><i class="fa fa-check"></i>AZT和AIDS</a></li>
</ul></li>
<li class="chapter" data-level="4.4" data-path="logistic-regression.html"><a href="logistic-regression.html#multi-logistic"><i class="fa fa-check"></i><b>4.4</b> 多元logistic回归</a><ul>
<li class="chapter" data-level="" data-path="logistic-regression.html"><a href="logistic-regression.html#母鲎及其追随者多元logistic"><i class="fa fa-check"></i>母鲎及其追随者（多元logistic）</a></li>
</ul></li>
<li class="chapter" data-level="4.5" data-path="logistic-regression.html"><a href="logistic-regression.html#logistic回归效应的概括"><i class="fa fa-check"></i><b>4.5</b> logistic回归效应的概括</a></li>
<li class="chapter" data-level="" data-path="logistic-regression.html"><a href="logistic-regression.html#problem-ch4"><i class="fa fa-check"></i>课后题</a><ul>
<li class="chapter" data-level="" data-path="logistic-regression.html"><a href="logistic-regression.html#第8题"><i class="fa fa-check"></i>第8题</a></li>
<li class="chapter" data-level="" data-path="logistic-regression.html"><a href="logistic-regression.html#第24题"><i class="fa fa-check"></i>第24题</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="5" data-path="build-and-apply-logistic-model.html"><a href="build-and-apply-logistic-model.html"><i class="fa fa-check"></i><b>5</b> logistic回归模型的构建和应用</a><ul>
<li class="chapter" data-level="5.1" data-path="build-and-apply-logistic-model.html"><a href="build-and-apply-logistic-model.html#model-selection"><i class="fa fa-check"></i><b>5.1</b> 模型选择策略</a><ul>
<li class="chapter" data-level="" data-path="build-and-apply-logistic-model.html"><a href="build-and-apply-logistic-model.html#母鲎及其追随者模型选择"><i class="fa fa-check"></i>母鲎及其追随者（模型选择）</a></li>
<li class="chapter" data-level="" data-path="build-and-apply-logistic-model.html"><a href="build-and-apply-logistic-model.html#母鲎及其追随者预测功效"><i class="fa fa-check"></i>母鲎及其追随者（预测功效）</a></li>
</ul></li>
<li class="chapter" data-level="5.2" data-path="build-and-apply-logistic-model.html"><a href="build-and-apply-logistic-model.html#model-checking"><i class="fa fa-check"></i><b>5.2</b> 模型检验</a><ul>
<li class="chapter" data-level="" data-path="build-and-apply-logistic-model.html"><a href="build-and-apply-logistic-model.html#母鲎及其追随者模型lr检验"><i class="fa fa-check"></i>母鲎及其追随者（模型LR检验）</a></li>
<li class="chapter" data-level="" data-path="build-and-apply-logistic-model.html"><a href="build-and-apply-logistic-model.html#azt和aids拟合优度"><i class="fa fa-check"></i>AZT和AIDS（拟合优度）</a></li>
<li class="chapter" data-level="" data-path="build-and-apply-logistic-model.html"><a href="build-and-apply-logistic-model.html#母鲎及其追随者hm检验"><i class="fa fa-check"></i>母鲎及其追随者（HM检验）</a></li>
<li class="chapter" data-level="" data-path="build-and-apply-logistic-model.html"><a href="build-and-apply-logistic-model.html#佛罗里达大学研究生入学"><i class="fa fa-check"></i>佛罗里达大学研究生入学</a></li>
<li class="chapter" data-level="" data-path="build-and-apply-logistic-model.html"><a href="build-and-apply-logistic-model.html#心脏病与血压的关系"><i class="fa fa-check"></i>心脏病与血压的关系</a></li>
</ul></li>
<li class="chapter" data-level="5.3" data-path="build-and-apply-logistic-model.html"><a href="build-and-apply-logistic-model.html#sparse-data-logistic"><i class="fa fa-check"></i><b>5.3</b> 稀疏数据效应</a><ul>
<li class="chapter" data-level="" data-path="build-and-apply-logistic-model.html"><a href="build-and-apply-logistic-model.html#稀疏数据的临床试验结果"><i class="fa fa-check"></i>稀疏数据的临床试验结果</a></li>
</ul></li>
<li class="chapter" data-level="5.4" data-path="build-and-apply-logistic-model.html"><a href="build-and-apply-logistic-model.html#conditional-logistic"><i class="fa fa-check"></i><b>5.4</b> 条件logistic回归与精确推断</a><ul>
<li class="chapter" data-level="" data-path="build-and-apply-logistic-model.html"><a href="build-and-apply-logistic-model.html#晋升能力"><i class="fa fa-check"></i>晋升能力</a></li>
</ul></li>
<li class="chapter" data-level="5.5" data-path="build-and-apply-logistic-model.html"><a href="build-and-apply-logistic-model.html#logistic-sample-num"><i class="fa fa-check"></i><b>5.5</b> logistic回归的样本量与功效</a><ul>
<li class="chapter" data-level="" data-path="build-and-apply-logistic-model.html"><a href="build-and-apply-logistic-model.html#样本量计算"><i class="fa fa-check"></i>样本量计算</a></li>
</ul></li>
<li class="chapter" data-level="" data-path="build-and-apply-logistic-model.html"><a href="build-and-apply-logistic-model.html#problem-ch5"><i class="fa fa-check"></i>课后题</a><ul>
<li class="chapter" data-level="" data-path="build-and-apply-logistic-model.html"><a href="build-and-apply-logistic-model.html#第10题"><i class="fa fa-check"></i>第10题</a></li>
<li class="chapter" data-level="" data-path="build-and-apply-logistic-model.html"><a href="build-and-apply-logistic-model.html#第18题-1"><i class="fa fa-check"></i>第18题</a></li>
<li class="chapter" data-level="" data-path="build-and-apply-logistic-model.html"><a href="build-and-apply-logistic-model.html#第28题"><i class="fa fa-check"></i>第28题</a></li>
</ul></li>
</ul></li>
<li class="chapter" data-level="6" data-path="multi-logit-model.html"><a href="multi-logit-model.html"><i class="fa fa-check"></i><b>6</b> 多类别logit模型</a><ul>
<li class="chapter" data-level="6.1" data-path="multi-logit-model.html"><a href="multi-logit-model.html#nomial-logit"><i class="fa fa-check"></i><b>6.1</b> 名义响应变量的logit模型</a><ul>
<li class="chapter" data-level="" data-path="multi-logit-model.html"><a href="multi-logit-model.html#钝吻鳄食物选择"><i class="fa fa-check"></i>钝吻鳄食物选择</a></li>
<li class="chapter" data-level="" data-path="multi-logit-model.html"><a href="multi-logit-model.html#是否相信来世"><i class="fa fa-check"></i>是否相信来世</a></li>
</ul></li>
<li class="chapter" data-level="6.2" data-path="multi-logit-model.html"><a href="multi-logit-model.html#ordinal-logit"><i class="fa fa-check"></i><b>6.2</b> 有序响应变量的累积logit模型</a><ul>
<li class="chapter" data-level="" data-path="multi-logit-model.html"><a href="multi-logit-model.html#政治意识形态和隶属党派的关系"><i class="fa fa-check"></i>政治意识形态和隶属党派的关系</a></li>
<li class="chapter" data-level="" data-path="multi-logit-model.html"><a href="multi-logit-model.html#对心理健康建模"><i class="fa fa-check"></i>对心理健康建模</a></li>
</ul></li>
<li class="chapter" data-level="6.3" data-path="multi-logit-model.html"><a href="multi-logit-model.html#paired-ordinal-logit"><i class="fa fa-check"></i><b>6.3</b> 成对类别有序logit</a><ul>
<li class="chapter" data-level="" data-path="multi-logit-model.html"><a href="multi-logit-model.html#再访政治意识形态"><i class="fa fa-check"></i>再访政治意识形态</a></li>
<li class="chapter" data-level="" data-path="multi-logit-model.html"><a href="multi-logit-model.html#发育毒性研究"><i class="fa fa-check"></i>发育毒性研究</a></li>
</ul></li>
<li class="chapter" data-level="6.4" data-path="multi-logit-model.html"><a href="multi-logit-model.html#conditional-independent"><i class="fa fa-check"></i><b>6.4</b> 条件独立性检验</a><ul>
<li class="chapter" data-level="" data-path="multi-logit-model.html"><a href="multi-logit-model.html#工作满意度和收入"><i class="fa fa-check"></i>工作满意度和收入</a></li>
</ul></li>
<li class="chapter" data-level="" data-path="multi-logit-model.html"><a href="multi-logit-model.html#ch6-problems"><i class="fa fa-check"></i>课后题</a></li>
</ul></li>
<li class="appendix"><span><b>附录</b></span></li>
<li class="chapter" data-level="A" data-path="r-pkg-intro.html"><a href="r-pkg-intro.html"><i class="fa fa-check"></i><b>A</b> 配套R包使用介绍</a><ul>
<li class="chapter" data-level="A.1" data-path="r-pkg-intro.html"><a href="r-pkg-intro.html#r-pkg-install"><i class="fa fa-check"></i><b>A.1</b> 安装</a></li>
<li class="chapter" data-level="A.2" data-path="r-pkg-intro.html"><a href="r-pkg-intro.html#r-pkg-use"><i class="fa fa-check"></i><b>A.2</b> 使用说明</a></li>
</ul></li>
<li class="chapter" data-level="B" data-path="book-dataset-list.html"><a href="book-dataset-list.html"><i class="fa fa-check"></i><b>B</b> 教材数据列表</a><ul>
<li class="chapter" data-level="B.1" data-path="book-dataset-list.html"><a href="book-dataset-list.html#正文案例数据"><i class="fa fa-check"></i><b>B.1</b> 正文案例数据</a></li>
<li class="chapter" data-level="B.2" data-path="book-dataset-list.html"><a href="book-dataset-list.html#习题数据"><i class="fa fa-check"></i><b>B.2</b> 习题数据</a></li>
</ul></li>
<li class="divider"></li>
<li><a href="https://bookdown.org" target="blank">本书由 bookdown 强力驱动</a></li>

</ul>

      </nav>
    </div>

    <div class="book-body">
      <div class="body-inner">
        <div class="book-header" role="navigation">
          <h1>
            <i class="fa fa-circle-o-notch fa-spin"></i><a href="./">《属性数据分析》代码</a>
          </h1>
        </div>

        <div class="page-wrapper" tabindex="-1" role="main">
          <div class="page-inner">

            <section class="normal" id="section-">
<div id="multi-logit-model" class="section level1">
<h1><span class="header-section-number">第 6 章</span> 多类别logit模型</h1>
<div id="nomial-logit" class="section level2">
<h2><span class="header-section-number">6.1</span> 名义响应变量的logit模型</h2>
<div id="钝吻鳄食物选择" class="section level3 unnumbered">
<h3>钝吻鳄食物选择</h3>
<div class="sourceCode" id="cb351"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb351-1" data-line-number="1"><span class="kw">library</span>(VGAM)</a>
<a class="sourceLine" id="cb351-2" data-line-number="2"><span class="kw">library</span>(cdabookdb)</a>
<a class="sourceLine" id="cb351-3" data-line-number="3"><span class="kw">data</span>(<span class="st">&quot;alligators1&quot;</span>)</a>
<a class="sourceLine" id="cb351-4" data-line-number="4"></a>
<a class="sourceLine" id="cb351-5" data-line-number="5"><span class="co"># 拟合多类别logit模型</span></a>
<a class="sourceLine" id="cb351-6" data-line-number="6">alligators.fit1 &lt;-<span class="st"> </span><span class="kw">vglm</span>(</a>
<a class="sourceLine" id="cb351-7" data-line-number="7">  Food <span class="op">~</span><span class="st"> </span>Length,</a>
<a class="sourceLine" id="cb351-8" data-line-number="8">  <span class="dt">family =</span> multinomial, </a>
<a class="sourceLine" id="cb351-9" data-line-number="9">  <span class="dt">data=</span>alligators1</a>
<a class="sourceLine" id="cb351-10" data-line-number="10">)</a>
<a class="sourceLine" id="cb351-11" data-line-number="11"></a>
<a class="sourceLine" id="cb351-12" data-line-number="12"><span class="kw">summary</span>(alligators.fit1)</a></code></pre></div>
<pre><code>## 
## Call:
## vglm(formula = Food ~ Length, family = multinomial, data = alligators1)
## 
## 
## Pearson residuals:
##                      Min     1Q Median    3Q  Max
## log(mu[,1]/mu[,3]) -2.33 -0.507  0.554 0.684 1.45
## log(mu[,2]/mu[,3]) -2.69 -0.482 -0.165 0.709 3.44
## 
## Coefficients: 
##               Estimate Std. Error z value Pr(&gt;|z|)   
## (Intercept):1    1.618      1.307    1.24   0.2159   
## (Intercept):2    5.697      1.794    3.18   0.0015 **
## Length:1        -0.110      0.517   -0.21   0.8314   
## Length:2        -2.465      0.900      NA       NA   
## ---
## Signif. codes:  
## 0 &#39;***&#39; 0.001 &#39;**&#39; 0.01 &#39;*&#39; 0.05 &#39;.&#39; 0.1 &#39; &#39; 1
## 
## Number of linear predictors:  2 
## 
## Names of linear predictors: 
## log(mu[,1]/mu[,3]), log(mu[,2]/mu[,3])
## 
## Residual deviance: 98.34 on 114 degrees of freedom
## 
## Log-likelihood: -49.17 on 114 degrees of freedom
## 
## Number of iterations: 5 
## 
## Warning: Hauck-Donner effect detected in the following estimate(s):
## &#39;Length:2&#39;
## 
## Reference group is level  3  of the response</code></pre>
<p>以下画出短吻鳄食用三种食物的概率随着其长度的变化曲线。</p>
<div class="sourceCode" id="cb353"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb353-1" data-line-number="1">new_length_x &lt;-<span class="st"> </span><span class="kw">data.frame</span>(<span class="dt">Length =</span> <span class="kw">seq</span>(<span class="dv">0</span>, <span class="dv">5</span>, <span class="fl">0.1</span>))</a>
<a class="sourceLine" id="cb353-2" data-line-number="2">prob_food &lt;-<span class="st"> </span><span class="kw">predict</span>(alligators.fit1, new_length_x, <span class="dt">type =</span> <span class="st">&quot;response&quot;</span>)</a>
<a class="sourceLine" id="cb353-3" data-line-number="3"></a>
<a class="sourceLine" id="cb353-4" data-line-number="4"><span class="kw">plot</span>(</a>
<a class="sourceLine" id="cb353-5" data-line-number="5">  <span class="ot">NULL</span>,</a>
<a class="sourceLine" id="cb353-6" data-line-number="6">  <span class="dt">xlim =</span> <span class="kw">c</span>(<span class="dv">1</span>, <span class="dv">4</span>), <span class="dt">ylim =</span> <span class="kw">c</span>(<span class="dv">0</span>, <span class="dv">1</span>),</a>
<a class="sourceLine" id="cb353-7" data-line-number="7">  <span class="dt">xlab =</span> <span class="st">&quot;Length of Alligator&quot;</span>, <span class="dt">ylab =</span> <span class="st">&quot;Predictted Probability&quot;</span></a>
<a class="sourceLine" id="cb353-8" data-line-number="8">)</a>
<a class="sourceLine" id="cb353-9" data-line-number="9">food_col &lt;-<span class="st"> </span><span class="kw">c</span>(<span class="dt">F =</span> <span class="dv">2</span>, <span class="dt">I =</span> <span class="dv">3</span>, <span class="dt">O =</span> <span class="dv">5</span>)</a>
<a class="sourceLine" id="cb353-10" data-line-number="10"></a>
<a class="sourceLine" id="cb353-11" data-line-number="11"><span class="kw">sapply</span>(<span class="kw">c</span>(<span class="st">&quot;F&quot;</span>, <span class="st">&quot;I&quot;</span>, <span class="st">&quot;O&quot;</span>), <span class="cf">function</span>(food) {</a>
<a class="sourceLine" id="cb353-12" data-line-number="12">  <span class="kw">lines</span>(new_length_x<span class="op">$</span>Length, prob_food[, food], <span class="dt">col =</span> food_col[food])</a>
<a class="sourceLine" id="cb353-13" data-line-number="13">})</a>
<a class="sourceLine" id="cb353-14" data-line-number="14"></a>
<a class="sourceLine" id="cb353-15" data-line-number="15"><span class="kw">legend</span>(<span class="fl">1.75</span>, <span class="fl">0.95</span>, <span class="kw">c</span>(<span class="st">&quot;Fish&quot;</span>, <span class="st">&quot;Invertebrate&quot;</span>, <span class="st">&quot;Other&quot;</span>), <span class="dt">lty =</span> <span class="dv">1</span>, <span class="dt">col =</span> <span class="dv">2</span><span class="op">:</span><span class="dv">5</span>)</a></code></pre></div>
<p><img src="cdacode_files/figure-html/unnamed-chunk-134-1.png" width="70%" style="display: block; margin: auto;" /></p>
</div>
<div id="是否相信来世" class="section level3 unnumbered">
<h3>是否相信来世</h3>
<div class="sourceCode" id="cb354"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb354-1" data-line-number="1"><span class="kw">library</span>(VGAM)</a>
<a class="sourceLine" id="cb354-2" data-line-number="2"><span class="kw">library</span>(tidyr)</a>
<a class="sourceLine" id="cb354-3" data-line-number="3"><span class="kw">library</span>(cdabookdb)</a>
<a class="sourceLine" id="cb354-4" data-line-number="4"><span class="kw">data</span>(<span class="st">&quot;afterlife2&quot;</span>)</a>
<a class="sourceLine" id="cb354-5" data-line-number="5"><span class="kw">ftable</span>(afterlife2)</a></code></pre></div>
<pre><code>##              Believe Yes Undecided  No
## Race  Gender                          
## White Female         371        49  74
##       Male           250        45  71
## Black Female          64         9  15
##       Male            25         5  13</code></pre>
<div class="sourceCode" id="cb356"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb356-1" data-line-number="1">afterlife2_df &lt;-<span class="st"> </span><span class="kw">spread</span>(<span class="kw">as.data.frame</span>(afterlife2), Believe, Freq)</a>
<a class="sourceLine" id="cb356-2" data-line-number="2">afterlife2.fit1 &lt;-<span class="st"> </span><span class="kw">vglm</span>(</a>
<a class="sourceLine" id="cb356-3" data-line-number="3">  <span class="kw">cbind</span>(Yes, Undecided, No) <span class="op">~</span><span class="st"> </span>(Gender <span class="op">==</span><span class="st"> &quot;Female&quot;</span>) <span class="op">+</span><span class="st"> </span>(Race <span class="op">==</span><span class="st"> &quot;White&quot;</span>), </a>
<a class="sourceLine" id="cb356-4" data-line-number="4">  <span class="dt">data =</span> afterlife2_df, <span class="dt">family =</span> <span class="kw">multinomial</span>()</a>
<a class="sourceLine" id="cb356-5" data-line-number="5">)</a>
<a class="sourceLine" id="cb356-6" data-line-number="6"></a>
<a class="sourceLine" id="cb356-7" data-line-number="7"><span class="kw">summary</span>(afterlife2.fit1)</a></code></pre></div>
<pre><code>## 
## Call:
## vglm(formula = cbind(Yes, Undecided, No) ~ (Gender == &quot;Female&quot;) + 
##     (Race == &quot;White&quot;), family = multinomial(), data = afterlife2_df)
## 
## 
## Pearson residuals:
##   log(mu[,1]/mu[,3]) log(mu[,2]/mu[,3])
## 1             -0.219             -0.114
## 2              0.228              0.111
## 3              0.471              0.230
## 4             -0.618             -0.280
## 
## Coefficients: 
##                          Estimate Std. Error z value
## (Intercept):1               0.883      0.243    3.64
## (Intercept):2              -0.758      0.361   -2.10
## Gender == &quot;Female&quot;TRUE:1    0.419      0.171    2.44
## Gender == &quot;Female&quot;TRUE:2    0.105      0.247    0.43
## Race == &quot;White&quot;TRUE:1       0.342      0.237    1.44
## Race == &quot;White&quot;TRUE:2       0.271      0.354    0.77
##                          Pr(&gt;|z|)    
## (Intercept):1             0.00027 ***
## (Intercept):2             0.03593 *  
## Gender == &quot;Female&quot;TRUE:1  0.01452 *  
## Gender == &quot;Female&quot;TRUE:2  0.66996    
## Race == &quot;White&quot;TRUE:1     0.14934    
## Race == &quot;White&quot;TRUE:2     0.44416    
## ---
## Signif. codes:  
## 0 &#39;***&#39; 0.001 &#39;**&#39; 0.01 &#39;*&#39; 0.05 &#39;.&#39; 0.1 &#39; &#39; 1
## 
## Number of linear predictors:  2 
## 
## Names of linear predictors: 
## log(mu[,1]/mu[,3]), log(mu[,2]/mu[,3])
## 
## Residual deviance: 0.854 on 2 degrees of freedom
## 
## Log-likelihood: -19.73 on 2 degrees of freedom
## 
## Number of iterations: 3 
## 
## No Hauck-Donner effect found in any of the estimates
## 
## Reference group is level  3  of the response</code></pre>
<div class="sourceCode" id="cb358"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb358-1" data-line-number="1"><span class="kw">fitted</span>(afterlife2.fit1)</a></code></pre></div>
<pre><code>##      Yes Undecided     No
## 1 0.7546   0.09956 0.1459
## 2 0.6783   0.12245 0.1993
## 3 0.7074   0.10018 0.1925
## 4 0.6222   0.12056 0.2573</code></pre>
</div>
</div>
<div id="ordinal-logit" class="section level2">
<h2><span class="header-section-number">6.2</span> 有序响应变量的累积logit模型</h2>
<div id="政治意识形态和隶属党派的关系" class="section level3 unnumbered">
<h3>政治意识形态和隶属党派的关系</h3>
<div class="sourceCode" id="cb360"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb360-1" data-line-number="1"><span class="kw">library</span>(VGAM)</a>
<a class="sourceLine" id="cb360-2" data-line-number="2"><span class="kw">library</span>(tidyr)</a>
<a class="sourceLine" id="cb360-3" data-line-number="3"><span class="kw">library</span>(cdabookdb)</a>
<a class="sourceLine" id="cb360-4" data-line-number="4"><span class="kw">data</span>(<span class="st">&quot;ideology&quot;</span>)</a>
<a class="sourceLine" id="cb360-5" data-line-number="5"><span class="kw">ftable</span>(ideology)</a></code></pre></div>
<pre><code>##              Ideology VLib SLib Mod SCon VCon
## Gender Party                                 
## Female Dem              44   47 118   23   32
##        Rep              18   28  86   39   48
## Male   Dem              36   34  53   18   23
##        Rep              12   18  62   45   51</code></pre>
<div class="sourceCode" id="cb362"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb362-1" data-line-number="1">ideology_df &lt;-<span class="st"> </span><span class="kw">spread</span>(<span class="kw">as.data.frame</span>(ideology), Ideology, Freq)</a>
<a class="sourceLine" id="cb362-2" data-line-number="2"></a>
<a class="sourceLine" id="cb362-3" data-line-number="3">ide_m &lt;-<span class="st"> </span><span class="kw">vglm</span>(</a>
<a class="sourceLine" id="cb362-4" data-line-number="4">  <span class="kw">cbind</span>(VLib, SLib, Mod, SCon, VCon) <span class="op">~</span><span class="st"> </span>Party <span class="op">==</span><span class="st"> &quot;Dem&quot;</span>,</a>
<a class="sourceLine" id="cb362-5" data-line-number="5">  <span class="dt">data =</span> ideology_df,</a>
<a class="sourceLine" id="cb362-6" data-line-number="6">  <span class="dt">family =</span> <span class="kw">cumulative</span>(<span class="dt">parallel =</span> <span class="ot">TRUE</span>) <span class="co"># 累积概率且解释变量系数相同</span></a>
<a class="sourceLine" id="cb362-7" data-line-number="7">)</a>
<a class="sourceLine" id="cb362-8" data-line-number="8"><span class="kw">summary</span>(ide_m)</a></code></pre></div>
<pre><code>## 
## Call:
## vglm(formula = cbind(VLib, SLib, Mod, SCon, VCon) ~ Party == 
##     &quot;Dem&quot;, family = cumulative(parallel = TRUE), data = ideology_df)
## 
## 
## Pearson residuals:
##   logit(P[Y&lt;=1]) logit(P[Y&lt;=2]) logit(P[Y&lt;=3])
## 1        -0.4630         -1.272          1.506
## 2        -0.0773          0.759          0.914
## 3         1.0080          1.339         -0.605
## 4        -0.4888         -0.489         -2.064
##   logit(P[Y&lt;=4])
## 1         -0.681
## 2          0.918
## 3         -1.074
## 4          0.271
## 
## Coefficients: 
##                    Estimate Std. Error z value Pr(&gt;|z|)    
## (Intercept):1       -2.4690     0.1318  -18.73  &lt; 2e-16 ***
## (Intercept):2       -1.4745     0.1091  -13.52  &lt; 2e-16 ***
## (Intercept):3        0.2371     0.0948    2.50    0.012 *  
## (Intercept):4        1.0695     0.1046   10.23  &lt; 2e-16 ***
## Party == &quot;Dem&quot;TRUE   0.9745     0.1291    7.55  4.3e-14 ***
## ---
## Signif. codes:  
## 0 &#39;***&#39; 0.001 &#39;**&#39; 0.01 &#39;*&#39; 0.05 &#39;.&#39; 0.1 &#39; &#39; 1
## 
## Number of linear predictors:  4 
## 
## Names of linear predictors: 
## logit(P[Y&lt;=1]), logit(P[Y&lt;=2]), logit(P[Y&lt;=3]), logit(P[Y&lt;=4])
## 
## Residual deviance: 15.9 on 11 degrees of freedom
## 
## Log-likelihood: -47.84 on 11 degrees of freedom
## 
## Number of iterations: 4 
## 
## No Hauck-Donner effect found in any of the estimates
## 
## Exponentiated coefficients:
## Party == &quot;Dem&quot;TRUE 
##               2.65</code></pre>
</div>
<div id="对心理健康建模" class="section level3 unnumbered">
<h3>对心理健康建模</h3>
<div class="sourceCode" id="cb364"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb364-1" data-line-number="1"><span class="kw">library</span>(VGAM)</a>
<a class="sourceLine" id="cb364-2" data-line-number="2"><span class="kw">library</span>(cdabookdb)</a>
<a class="sourceLine" id="cb364-3" data-line-number="3"><span class="kw">data</span>(<span class="st">&quot;impairment&quot;</span>)</a>
<a class="sourceLine" id="cb364-4" data-line-number="4"></a>
<a class="sourceLine" id="cb364-5" data-line-number="5"></a>
<a class="sourceLine" id="cb364-6" data-line-number="6">impairment_m &lt;-<span class="st"> </span><span class="kw">vglm</span>(</a>
<a class="sourceLine" id="cb364-7" data-line-number="7">  Impairment <span class="op">~</span><span class="st"> </span>SES <span class="op">+</span><span class="st"> </span>LifeEvents,</a>
<a class="sourceLine" id="cb364-8" data-line-number="8">  <span class="dt">family =</span> <span class="kw">cumulative</span>(<span class="dt">parallel =</span> <span class="ot">TRUE</span>), <span class="co"># 累积概率且解释变量系数相同</span></a>
<a class="sourceLine" id="cb364-9" data-line-number="9">  <span class="dt">data =</span> impairment</a>
<a class="sourceLine" id="cb364-10" data-line-number="10">)</a></code></pre></div>
<pre><code>## Warning in eval(slot(family, &quot;initialize&quot;)): response should
## be ordinal---see ordered()</code></pre>
<div class="sourceCode" id="cb366"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb366-1" data-line-number="1"><span class="kw">summary</span>(impairment_m)</a></code></pre></div>
<pre><code>## 
## Call:
## vglm(formula = Impairment ~ SES + LifeEvents, family = cumulative(parallel = TRUE), 
##     data = impairment)
## 
## 
## Pearson residuals:
##                  Min     1Q Median    3Q  Max
## logit(P[Y&lt;=1]) -1.57 -0.705 -0.210 0.807 2.71
## logit(P[Y&lt;=2]) -2.33 -0.467  0.266 0.690 1.61
## logit(P[Y&lt;=3]) -3.69  0.120  0.204 0.419 1.89
## 
## Coefficients: 
##               Estimate Std. Error z value Pr(&gt;|z|)   
## (Intercept):1   -0.282      0.623   -0.45   0.6510   
## (Intercept):2    1.213      0.651    1.86   0.0625 . 
## (Intercept):3    2.209      0.717    3.08   0.0021 **
## SES              1.111      0.614    1.81   0.0704 . 
## LifeEvents      -0.319      0.119   -2.67   0.0076 **
## ---
## Signif. codes:  
## 0 &#39;***&#39; 0.001 &#39;**&#39; 0.01 &#39;*&#39; 0.05 &#39;.&#39; 0.1 &#39; &#39; 1
## 
## Number of linear predictors:  3 
## 
## Names of linear predictors: 
## logit(P[Y&lt;=1]), logit(P[Y&lt;=2]), logit(P[Y&lt;=3])
## 
## Residual deviance: 99.1 on 115 degrees of freedom
## 
## Log-likelihood: -49.55 on 115 degrees of freedom
## 
## Number of iterations: 5 
## 
## No Hauck-Donner effect found in any of the estimates
## 
## Exponentiated coefficients:
##        SES LifeEvents 
##      3.038      0.727</code></pre>
</div>
</div>
<div id="paired-ordinal-logit" class="section level2">
<h2><span class="header-section-number">6.3</span> 成对类别有序logit</h2>
<div id="再访政治意识形态" class="section level3 unnumbered">
<h3>再访政治意识形态</h3>
<div class="sourceCode" id="cb368"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb368-1" data-line-number="1"><span class="kw">library</span>(VGAM)</a>
<a class="sourceLine" id="cb368-2" data-line-number="2"><span class="kw">library</span>(tidyr)</a>
<a class="sourceLine" id="cb368-3" data-line-number="3"><span class="kw">library</span>(cdabookdb)</a>
<a class="sourceLine" id="cb368-4" data-line-number="4"><span class="kw">data</span>(<span class="st">&quot;ideology&quot;</span>)</a>
<a class="sourceLine" id="cb368-5" data-line-number="5"><span class="kw">ftable</span>(ideology)</a></code></pre></div>
<pre><code>##              Ideology VLib SLib Mod SCon VCon
## Gender Party                                 
## Female Dem              44   47 118   23   32
##        Rep              18   28  86   39   48
## Male   Dem              36   34  53   18   23
##        Rep              12   18  62   45   51</code></pre>
<div class="sourceCode" id="cb370"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb370-1" data-line-number="1">ideology_df &lt;-<span class="st"> </span><span class="kw">spread</span>(<span class="kw">as.data.frame</span>(ideology), Ideology, Freq)</a>
<a class="sourceLine" id="cb370-2" data-line-number="2"></a>
<a class="sourceLine" id="cb370-3" data-line-number="3">ide_m &lt;-<span class="st"> </span><span class="kw">vglm</span>(</a>
<a class="sourceLine" id="cb370-4" data-line-number="4">  <span class="kw">cbind</span>(VLib, SLib, Mod, SCon, VCon) <span class="op">~</span><span class="st"> </span>Party <span class="op">==</span><span class="st"> &quot;Dem&quot;</span>,</a>
<a class="sourceLine" id="cb370-5" data-line-number="5">  <span class="dt">data =</span> ideology_df,</a>
<a class="sourceLine" id="cb370-6" data-line-number="6">  <span class="co"># 相邻类别logit，更高且系数相同</span></a>
<a class="sourceLine" id="cb370-7" data-line-number="7">  <span class="dt">family =</span> <span class="kw">acat</span>(<span class="dt">reverse =</span> <span class="ot">TRUE</span>, <span class="dt">parallel =</span> <span class="ot">TRUE</span>) </a>
<a class="sourceLine" id="cb370-8" data-line-number="8">) </a></code></pre></div>
<pre><code>## Warning in vglm.fitter(x = x, y = y, w = w, offset = offset,
## Xm2 = Xm2, : some quantities such as z, residuals, SEs may
## be inaccurate due to convergence at a half-step</code></pre>
<div class="sourceCode" id="cb372"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb372-1" data-line-number="1"><span class="kw">summary</span>(ide_m)</a></code></pre></div>
<pre><code>## 
## Call:
## vglm(formula = cbind(VLib, SLib, Mod, SCon, VCon) ~ Party == 
##     &quot;Dem&quot;, family = acat(reverse = TRUE, parallel = TRUE), data = ideology_df)
## 
## 
## Pearson residuals:
##   loge(P[Y=1]/P[Y=2]) loge(P[Y=2]/P[Y=3])
## 1              -0.595              -1.117
## 2               0.125               0.463
## 3               0.714               1.505
## 4              -0.106              -0.620
##   loge(P[Y=3]/P[Y=4]) loge(P[Y=4]/P[Y=5])
## 1               1.730              -0.948
## 2               0.833               1.057
## 3              -0.525              -1.190
## 4              -2.247               0.554
## 
## Coefficients: 
##                    Estimate Std. Error z value Pr(&gt;|z|)    
## (Intercept):1        -0.439      0.140   -3.14   0.0017 ** 
## (Intercept):2        -1.172      0.112  -10.46  &lt; 2e-16 ***
## (Intercept):3         0.732      0.109    6.72  1.8e-11 ***
## (Intercept):4        -0.368      0.121   -3.03   0.0025 ** 
## Party == &quot;Dem&quot;TRUE    0.435      0.060    7.25  4.1e-13 ***
## ---
## Signif. codes:  
## 0 &#39;***&#39; 0.001 &#39;**&#39; 0.01 &#39;*&#39; 0.05 &#39;.&#39; 0.1 &#39; &#39; 1
## 
## Number of linear predictors:  4 
## 
## Names of linear predictors: 
## loge(P[Y=1]/P[Y=2]), loge(P[Y=2]/P[Y=3]), loge(P[Y=3]/P[Y=4]), loge(P[Y=4]/P[Y=5])
## 
## Residual deviance: 17.73 on 11 degrees of freedom
## 
## Log-likelihood: -48.75 on 11 degrees of freedom
## 
## Number of iterations: 4 
## 
## No Hauck-Donner effect found in any of the estimates</code></pre>
</div>
<div id="发育毒性研究" class="section level3 unnumbered">
<h3>发育毒性研究</h3>
<div class="sourceCode" id="cb374"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb374-1" data-line-number="1"><span class="kw">library</span>(VGAM)</a>
<a class="sourceLine" id="cb374-2" data-line-number="2"><span class="kw">library</span>(tidyr)</a>
<a class="sourceLine" id="cb374-3" data-line-number="3"><span class="kw">library</span>(cdabookdb)</a>
<a class="sourceLine" id="cb374-4" data-line-number="4"><span class="kw">data</span>(<span class="st">&quot;toxicity&quot;</span>)</a>
<a class="sourceLine" id="cb374-5" data-line-number="5"></a>
<a class="sourceLine" id="cb374-6" data-line-number="6">concentration &lt;-<span class="st"> </span><span class="kw">as.numeric</span>(<span class="kw">rownames</span>(toxicity))</a>
<a class="sourceLine" id="cb374-7" data-line-number="7">toxicity.fit.cratio &lt;-<span class="st"> </span><span class="kw">vglm</span>(</a>
<a class="sourceLine" id="cb374-8" data-line-number="8">  <span class="kw">unclass</span>(toxicity) <span class="op">~</span><span class="st"> </span>concentration,</a>
<a class="sourceLine" id="cb374-9" data-line-number="9">  <span class="dt">family=</span><span class="kw">cratio</span>(<span class="dt">reverse =</span> <span class="ot">FALSE</span>, <span class="dt">parallel =</span> <span class="ot">FALSE</span>)</a>
<a class="sourceLine" id="cb374-10" data-line-number="10">)</a>
<a class="sourceLine" id="cb374-11" data-line-number="11"><span class="kw">summary</span>(toxicity.fit.cratio)</a></code></pre></div>
<pre><code>## 
## Call:
## vglm(formula = unclass(toxicity) ~ concentration, family = cratio(reverse = FALSE, 
##     parallel = FALSE))
## 
## 
## Pearson residuals:
##      logit(P[Y&gt;1|Y&gt;=1]) logit(P[Y&gt;2|Y&gt;=2])
## 0                -1.190             -0.063
## 62.5             -1.060              1.480
## 125               0.586              0.446
## 250               1.596             -0.879
## 500              -0.629              0.858
## 
## Coefficients: 
##                  Estimate Std. Error z value Pr(&gt;|z|)    
## (Intercept):1    3.247934   0.157660    20.6   &lt;2e-16 ***
## (Intercept):2    5.701902   0.330652    17.2   &lt;2e-16 ***
## concentration:1 -0.006389   0.000435   -14.7   &lt;2e-16 ***
## concentration:2 -0.017375   0.001213   -14.3   &lt;2e-16 ***
## ---
## Signif. codes:  
## 0 &#39;***&#39; 0.001 &#39;**&#39; 0.01 &#39;*&#39; 0.05 &#39;.&#39; 0.1 &#39; &#39; 1
## 
## Number of linear predictors:  2 
## 
## Names of linear predictors: 
## logit(P[Y&gt;1|Y&gt;=1]), logit(P[Y&gt;2|Y&gt;=2])
## 
## Residual deviance: 11.84 on 6 degrees of freedom
## 
## Log-likelihood: -26.35 on 6 degrees of freedom
## 
## Number of iterations: 5 
## 
## Warning: Hauck-Donner effect detected in the following estimate(s):
## &#39;(Intercept):1&#39;, &#39;concentration:2&#39;</code></pre>
<p>此处结课本符号相反：课本计算的是<span class="math inline">\(\mathrm{logit}(P[Y=1|Y&gt;=1])\)</span>和<span class="math inline">\(\mathrm{logit}(P[Y=2|Y&gt;=2])\)</span>，
这里计算的是<span class="math inline">\(\mathrm{logit}(P[Y&gt;1|Y&gt;=1])\)</span>和<span class="math inline">\(\mathrm{logit}(P[Y&gt;2|Y&gt;=2])\)</span></p>
</div>
</div>
<div id="conditional-independent" class="section level2">
<h2><span class="header-section-number">6.4</span> 条件独立性检验</h2>
<div id="工作满意度和收入" class="section level3 unnumbered">
<h3>工作满意度和收入</h3>
<div class="sourceCode" id="cb376"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb376-1" data-line-number="1"><span class="kw">library</span>(cdabookdb)</a>
<a class="sourceLine" id="cb376-2" data-line-number="2"><span class="kw">data</span>(<span class="st">&quot;job_satisfaction2&quot;</span>)</a></code></pre></div>
<div class="sourceCode" id="cb377"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb377-1" data-line-number="1">gender &lt;-<span class="st"> </span><span class="kw">factor</span>(</a>
<a class="sourceLine" id="cb377-2" data-line-number="2">  <span class="kw">rep</span>(<span class="kw">dimnames</span>(job_satisfaction2)<span class="op">$</span>Gender, <span class="dt">each =</span> <span class="dv">4</span>), </a>
<a class="sourceLine" id="cb377-3" data-line-number="3">  <span class="kw">dimnames</span>(job_satisfaction2)<span class="op">$</span>Gender</a>
<a class="sourceLine" id="cb377-4" data-line-number="4">)</a>
<a class="sourceLine" id="cb377-5" data-line-number="5">income &lt;-<span class="st"> </span><span class="kw">rep</span>(<span class="kw">c</span>(<span class="dv">3</span>, <span class="dv">10</span>, <span class="dv">20</span>, <span class="dv">35</span>), <span class="dt">times =</span> <span class="dv">2</span>)</a></code></pre></div>
<p>首先拟合两个累积logit模型（考虑收入效应和不考虑收入效应）</p>
<div class="sourceCode" id="cb378"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb378-1" data-line-number="1"><span class="co"># 有收入效应的模型</span></a>
<a class="sourceLine" id="cb378-2" data-line-number="2">job2.fit1 &lt;-<span class="st"> </span><span class="kw">vglm</span>(</a>
<a class="sourceLine" id="cb378-3" data-line-number="3">  <span class="kw">as.matrix</span>(<span class="kw">ftable</span>(job_satisfaction2)) <span class="op">~</span><span class="st"> </span>gender <span class="op">+</span><span class="st"> </span>income,</a>
<a class="sourceLine" id="cb378-4" data-line-number="4">  <span class="dt">family =</span> <span class="kw">cumulative</span>(<span class="dt">parallel =</span> <span class="ot">TRUE</span>)</a>
<a class="sourceLine" id="cb378-5" data-line-number="5">)</a>
<a class="sourceLine" id="cb378-6" data-line-number="6"><span class="kw">summary</span>(job2.fit1)</a></code></pre></div>
<pre><code>## 
## Call:
## vglm(formula = as.matrix(ftable(job_satisfaction2)) ~ gender + 
##     income, family = cumulative(parallel = TRUE))
## 
## 
## Pearson residuals:
##                   Min     1Q  Median    3Q   Max
## logit(P[Y&lt;=1]) -0.858 -0.588 -0.4348 0.201 1.270
## logit(P[Y&lt;=2]) -1.200 -0.457 -0.1883 0.652 2.044
## logit(P[Y&lt;=3]) -1.008 -0.371  0.0964 0.396 0.589
## 
## Coefficients: 
##               Estimate Std. Error z value Pr(&gt;|z|)    
## (Intercept):1  -2.5795     0.5618   -4.59  4.4e-06 ***
## (Intercept):2  -0.8939     0.3603   -2.48    0.013 *  
## (Intercept):3   2.0781     0.4206    4.94  7.8e-07 ***
## genderMale     -0.0257     0.4274   -0.06    0.952    
## income         -0.0444     0.0185   -2.40    0.017 *  
## ---
## Signif. codes:  
## 0 &#39;***&#39; 0.001 &#39;**&#39; 0.01 &#39;*&#39; 0.05 &#39;.&#39; 0.1 &#39; &#39; 1
## 
## Number of linear predictors:  3 
## 
## Names of linear predictors: 
## logit(P[Y&lt;=1]), logit(P[Y&lt;=2]), logit(P[Y&lt;=3])
## 
## Residual deviance: 13.95 on 19 degrees of freedom
## 
## Log-likelihood: -28.06 on 19 degrees of freedom
## 
## Number of iterations: 5 
## 
## No Hauck-Donner effect found in any of the estimates
## 
## Exponentiated coefficients:
## genderMale     income 
##     0.9747     0.9565</code></pre>
<div class="sourceCode" id="cb380"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb380-1" data-line-number="1"><span class="co"># 没有收入效应的模型</span></a>
<a class="sourceLine" id="cb380-2" data-line-number="2">job2.fit2 &lt;-<span class="st"> </span><span class="kw">vglm</span>(</a>
<a class="sourceLine" id="cb380-3" data-line-number="3">  <span class="kw">as.matrix</span>(<span class="kw">ftable</span>(job_satisfaction2)) <span class="op">~</span><span class="st"> </span>gender,</a>
<a class="sourceLine" id="cb380-4" data-line-number="4">  <span class="dt">family =</span> <span class="kw">cumulative</span>(<span class="dt">parallel =</span> <span class="ot">TRUE</span>)</a>
<a class="sourceLine" id="cb380-5" data-line-number="5">)</a>
<a class="sourceLine" id="cb380-6" data-line-number="6"><span class="kw">summary</span>(job2.fit2)</a></code></pre></div>
<pre><code>## 
## Call:
## vglm(formula = as.matrix(ftable(job_satisfaction2)) ~ gender, 
##     family = cumulative(parallel = TRUE))
## 
## 
## Pearson residuals:
##                   Min     1Q   Median    3Q   Max
## logit(P[Y&lt;=1]) -0.842 -0.655 -0.48385 0.403 2.105
## logit(P[Y&lt;=2]) -1.208 -0.698 -0.02072 0.796 1.961
## logit(P[Y&lt;=3]) -1.424 -0.553 -0.00333 0.780 0.924
## 
## Coefficients: 
##               Estimate Std. Error z value Pr(&gt;|z|)    
## (Intercept):1   -3.078      0.526   -5.85  4.9e-09 ***
## (Intercept):2   -1.420      0.293   -4.85  1.2e-06 ***
## (Intercept):3    1.426      0.293    4.87  1.1e-06 ***
## genderMale      -0.412      0.402   -1.02     0.31    
## ---
## Signif. codes:  
## 0 &#39;***&#39; 0.001 &#39;**&#39; 0.01 &#39;*&#39; 0.05 &#39;.&#39; 0.1 &#39; &#39; 1
## 
## Number of linear predictors:  3 
## 
## Names of linear predictors: 
## logit(P[Y&lt;=1]), logit(P[Y&lt;=2]), logit(P[Y&lt;=3])
## 
## Residual deviance: 19.62 on 20 degrees of freedom
## 
## Log-likelihood: -30.89 on 20 degrees of freedom
## 
## Number of iterations: 5 
## 
## Warning: Hauck-Donner effect detected in the following estimate(s):
## &#39;(Intercept):1&#39;
## 
## Exponentiated coefficients:
## genderMale 
##     0.6626</code></pre>
<p>接着对比两个模型</p>
<div class="sourceCode" id="cb382"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb382-1" data-line-number="1"><span class="co"># 对比两个模型</span></a>
<a class="sourceLine" id="cb382-2" data-line-number="2"><span class="kw">c</span>(<span class="dt">deviance =</span> <span class="kw">deviance</span>(job2.fit1), <span class="dt">df =</span> <span class="kw">df.residual</span>(job2.fit1))</a></code></pre></div>
<pre><code>## deviance       df 
##    13.95    19.00</code></pre>
<div class="sourceCode" id="cb384"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb384-1" data-line-number="1"><span class="kw">c</span>(<span class="dt">deviance =</span> <span class="kw">deviance</span>(job2.fit2), <span class="dt">df =</span> <span class="kw">df.residual</span>(job2.fit2))</a></code></pre></div>
<pre><code>## deviance       df 
##    19.62    20.00</code></pre>
<div class="sourceCode" id="cb386"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb386-1" data-line-number="1">df_diff &lt;-<span class="st"> </span><span class="kw">df.residual</span>(job2.fit2) <span class="op">-</span><span class="st"> </span><span class="kw">df.residual</span>(job2.fit1)</a>
<a class="sourceLine" id="cb386-2" data-line-number="2">deviance_diff &lt;-<span class="st"> </span><span class="kw">deviance</span>(job2.fit2) <span class="op">-</span><span class="st"> </span><span class="kw">deviance</span>(job2.fit1)</a>
<a class="sourceLine" id="cb386-3" data-line-number="3"><span class="dv">1</span> <span class="op">-</span><span class="st"> </span><span class="kw">pchisq</span>(deviance_diff, df_diff)</a></code></pre></div>
<pre><code>## [1] 0.01725</code></pre>
<p>接着拟合两个基线-类别logit模型，再进行对比（这次收入是因子而不是数值）</p>
<div class="sourceCode" id="cb388"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb388-1" data-line-number="1">income_factor &lt;-<span class="st"> </span><span class="kw">factor</span>(income)</a>
<a class="sourceLine" id="cb388-2" data-line-number="2"><span class="co"># 有收入效应的模型</span></a>
<a class="sourceLine" id="cb388-3" data-line-number="3">job2.fit3 &lt;-<span class="st"> </span><span class="kw">vglm</span>(</a>
<a class="sourceLine" id="cb388-4" data-line-number="4">  <span class="kw">as.matrix</span>(<span class="kw">ftable</span>(job_satisfaction2)) <span class="op">~</span><span class="st"> </span>gender <span class="op">+</span><span class="st"> </span>income_factor,</a>
<a class="sourceLine" id="cb388-5" data-line-number="5">  <span class="dt">family =</span> <span class="kw">multinomial</span>()</a>
<a class="sourceLine" id="cb388-6" data-line-number="6">)</a>
<a class="sourceLine" id="cb388-7" data-line-number="7"><span class="kw">summary</span>(job2.fit3)</a></code></pre></div>
<pre><code>## 
## Call:
## vglm(formula = as.matrix(ftable(job_satisfaction2)) ~ gender + 
##     income_factor, family = multinomial())
## 
## 
## Pearson residuals:
##                    log(mu[,1]/mu[,4]) log(mu[,2]/mu[,4])
## Female_&lt;5000                -3.50e-01              0.065
## Female_5000-15000            4.15e-01             -0.687
## Female_15000-25000          -1.36e-05              0.474
## Female_&gt;25000                1.62e-05              1.069
## Male_&lt;5000                   6.52e-01             -0.106
## Male_5000-15000             -6.86e-01              1.121
## Male_15000-25000             1.44e-05             -0.564
## Male_&gt;25000                 -1.03e-05             -0.748
##                    log(mu[,3]/mu[,4])
## Female_&lt;5000                    0.403
## Female_5000-15000               0.128
## Female_15000-25000             -0.507
## Female_&gt;25000                  -0.194
## Male_&lt;5000                     -0.731
## Male_5000-15000                -0.221
## Male_15000-25000                0.590
## Male_&gt;25000                     0.145
## 
## Coefficients: 
##                    Estimate Std. Error z value Pr(&gt;|z|)  
## (Intercept):1       -0.3785     0.9613   -0.39    0.694  
## (Intercept):2        0.3108     0.7859    0.40    0.692  
## (Intercept):3        1.5077     0.6539    2.31    0.021 *
## genderMale:1        -0.1122     1.2827   -0.09    0.930  
## genderMale:2        -0.0956     0.7676   -0.12    0.901  
## genderMale:3        -0.1761     0.5331   -0.33    0.741  
## income_factor10:1   -0.2832     1.2594   -0.22    0.822  
## income_factor10:2    0.1216     1.0005    0.12    0.903  
## income_factor10:3    0.2454     0.8406    0.29    0.770  
## income_factor20:1  -19.3686  4263.9687      NA       NA  
## income_factor20:2   -2.3489     1.3149   -1.79    0.074 .
## income_factor20:3   -0.8046     0.7825   -1.03    0.304  
## income_factor35:1  -19.2924  4161.9671      NA       NA  
## income_factor35:2   -1.2266     1.0740   -1.14    0.253  
## income_factor35:3   -0.9040     0.8160   -1.11    0.268  
## ---
## Signif. codes:  
## 0 &#39;***&#39; 0.001 &#39;**&#39; 0.01 &#39;*&#39; 0.05 &#39;.&#39; 0.1 &#39; &#39; 1
## 
## Number of linear predictors:  3 
## 
## Names of linear predictors: 
## log(mu[,1]/mu[,4]), log(mu[,2]/mu[,4]), log(mu[,3]/mu[,4])
## 
## Residual deviance: 7.093 on 9 degrees of freedom
## 
## Log-likelihood: -24.63 on 9 degrees of freedom
## 
## Number of iterations: 17 
## 
## Warning: Hauck-Donner effect detected in the following estimate(s):
## &#39;income_factor20:1&#39;, &#39;income_factor35:1&#39;
## 
## Reference group is level  4  of the response</code></pre>
<div class="sourceCode" id="cb390"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb390-1" data-line-number="1"><span class="co"># 没有收入效应的模型</span></a>
<a class="sourceLine" id="cb390-2" data-line-number="2">job2.fit4 &lt;-<span class="st"> </span><span class="kw">vglm</span>(</a>
<a class="sourceLine" id="cb390-3" data-line-number="3">  <span class="kw">as.matrix</span>(<span class="kw">ftable</span>(job_satisfaction2)) <span class="op">~</span><span class="st"> </span>gender,</a>
<a class="sourceLine" id="cb390-4" data-line-number="4">  <span class="dt">family =</span> <span class="kw">multinomial</span>()</a>
<a class="sourceLine" id="cb390-5" data-line-number="5">)</a>
<a class="sourceLine" id="cb390-6" data-line-number="6"><span class="kw">summary</span>(job2.fit4)</a></code></pre></div>
<pre><code>## 
## Call:
## vglm(formula = as.matrix(ftable(job_satisfaction2)) ~ gender, 
##     family = multinomial())
## 
## 
## Pearson residuals:
##                       Min     1Q  Median    3Q   Max
## log(mu[,1]/mu[,4]) -1.169 -0.738 -0.4024 0.536 2.482
## log(mu[,2]/mu[,4]) -1.145 -0.948  0.2135 0.620 2.021
## log(mu[,3]/mu[,4]) -0.818 -0.618 -0.0343 0.430 0.679
## 
## Coefficients: 
##               Estimate Std. Error z value Pr(&gt;|z|)    
## (Intercept):1   -1.386      0.645   -2.15  0.03174 *  
## (Intercept):2   -0.288      0.441   -0.65  0.51414    
## (Intercept):3    1.204      0.329    3.66  0.00025 ***
## genderMale:1    -1.012      1.228   -0.82  0.41000    
## genderMale:2    -0.501      0.697   -0.72  0.47226    
## genderMale:3    -0.466      0.493   -0.95  0.34383    
## ---
## Signif. codes:  
## 0 &#39;***&#39; 0.001 &#39;**&#39; 0.01 &#39;*&#39; 0.05 &#39;.&#39; 0.1 &#39; &#39; 1
## 
## Number of linear predictors:  3 
## 
## Names of linear predictors: 
## log(mu[,1]/mu[,4]), log(mu[,2]/mu[,4]), log(mu[,3]/mu[,4])
## 
## Residual deviance: 19.37 on 18 degrees of freedom
## 
## Log-likelihood: -30.76 on 18 degrees of freedom
## 
## Number of iterations: 5 
## 
## No Hauck-Donner effect found in any of the estimates
## 
## Reference group is level  4  of the response</code></pre>
<div class="sourceCode" id="cb392"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb392-1" data-line-number="1"><span class="co"># 对比两个模型</span></a>
<a class="sourceLine" id="cb392-2" data-line-number="2"><span class="kw">c</span>(<span class="dt">deviance =</span> <span class="kw">deviance</span>(job2.fit3), <span class="dt">df =</span> <span class="kw">df.residual</span>(job2.fit3))</a></code></pre></div>
<pre><code>## deviance       df 
##    7.093    9.000</code></pre>
<div class="sourceCode" id="cb394"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb394-1" data-line-number="1"><span class="kw">c</span>(<span class="dt">deviance =</span> <span class="kw">deviance</span>(job2.fit4), <span class="dt">df =</span> <span class="kw">df.residual</span>(job2.fit4))</a></code></pre></div>
<pre><code>## deviance       df 
##    19.37    18.00</code></pre>
<div class="sourceCode" id="cb396"><pre class="sourceCode r"><code class="sourceCode r"><a class="sourceLine" id="cb396-1" data-line-number="1">df_diff &lt;-<span class="st"> </span><span class="kw">df.residual</span>(job2.fit4) <span class="op">-</span><span class="st"> </span><span class="kw">df.residual</span>(job2.fit3)</a>
<a class="sourceLine" id="cb396-2" data-line-number="2">deviance_diff &lt;-<span class="st"> </span><span class="kw">deviance</span>(job2.fit4) <span class="op">-</span><span class="st"> </span><span class="kw">deviance</span>(job2.fit3)</a>
<a class="sourceLine" id="cb396-3" data-line-number="3"><span class="dv">1</span> <span class="op">-</span><span class="st"> </span><span class="kw">pchisq</span>(deviance_diff, df_diff)</a></code></pre></div>
<pre><code>## [1] 0.1983</code></pre>
</div>
</div>
<div id="ch6-problems" class="section level2 unnumbered">
<h2>课后题</h2>


</div>
</div>



            </section>

          </div>
        </div>
      </div>
<a href="build-and-apply-logistic-model.html" class="navigation navigation-prev " aria-label="Previous page"><i class="fa fa-angle-left"></i></a>
<a href="r-pkg-intro.html" class="navigation navigation-next " aria-label="Next page"><i class="fa fa-angle-right"></i></a>
    </div>
  </div>
<script src="libs/gitbook/js/app.min.js"></script>
<script src="libs/gitbook/js/lunr.js"></script>
<script src="libs/gitbook/js/plugin-search.js"></script>
<script src="libs/gitbook/js/plugin-sharing.js"></script>
<script src="libs/gitbook/js/plugin-fontsettings.js"></script>
<script src="libs/gitbook/js/plugin-bookdown.js"></script>
<script src="libs/gitbook/js/jquery.highlight.js"></script>
<script>
gitbook.require(["gitbook"], function(gitbook) {
gitbook.start({
"sharing": {
"github": true,
"facebook": false,
"twitter": false,
"google": false,
"linkedin": false,
"weibo": false,
"instapper": false,
"vk": false,
"all": ["facebook", "google", "twitter", "linkedin", "weibo", "instapaper"]
},
"fontsettings": {
"theme": "white",
"family": "sans",
"size": 2
},
"edit": {
"link": "https://github.com/jinzhen-lin/cdacode-document/edit/master/06-multi-logit-model.Rmd",
"text": "编辑"
},
"download": ["cdacode.pdf", "cdacode.epub", "cdacode.zip"],
"toc": {
"collapse": "section"
}
});
});
</script>

<!-- dynamically load mathjax for compatibility with self-contained -->
<script>
  (function () {
    var script = document.createElement("script");
    script.type = "text/javascript";
    var src = "true";
    if (src === "" || src === "true") src = "https://cdn.bootcss.com/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML";
    if (location.protocol !== "file:" && /^https?:/.test(src))
      src = src.replace(/^https?:/, '');
    script.src = src;
    document.getElementsByTagName("head")[0].appendChild(script);
  })();
</script>
</body>

</html>
